import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'dart:io';

import 'package:scanner/main/scanner/wj_scanner_logic.dart';

class WJScannerPage extends GetView<WJScannerLogic>  {

  const WJScannerPage({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<WJScannerLogic>(
      builder: (logic) {
       return Scaffold(
          appBar: AppBar(title: Text('文档扫描')),
          body: Obx(() => controller.isScanning.value
              ? Center(child: CircularProgressIndicator())
              : controller.scannedPaths.isEmpty
              ? Center(child: Text('未扫描任何文档'))
              : ListView.builder(
            itemCount: controller.scannedPaths.length,
            itemBuilder: (context, index) {
              final path = controller.scannedPaths[index];
              return path.endsWith('.pdf')
                  ? ListTile(
                title: Text('PDF 文件'),
                subtitle: Text(path.split('/').last),
                trailing: Icon(Icons.picture_as_pdf),
              )
                  : Image.file(File(path));
            },
          )),
          floatingActionButton: Column(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              FloatingActionButton(
                heroTag: 'scanImages',
                onPressed: () => controller.scanDocuments(),
                child: Icon(Icons.camera_alt),
                tooltip: '扫描文档',
              ),
              SizedBox(height: 16),
              FloatingActionButton(
                heroTag: 'scanPdf',
                onPressed: () => controller.scanToPdf(),
                child: Icon(Icons.picture_as_pdf),
                tooltip: '扫描为 PDF',
              ),
            ],
          ),
        );
      },
    );
  }
}